const path = require('path')
var name = path.basename(__filename, '.js')//本文件名

var resolve = (recvStr) => {
    var arr = recvStr.split(',')
    var result = {}
    if (!arr | arr.length != 9) {
        console.log(arr.length)
        result.status = false
        result.msg = '数据长度错误'
    } else {
        result.status = true
        result.msg = 'ok'
        result.data = {}
        result.data.type = arr[0].trim()
        result.data.totalJudge = arr[1].trim()
        result.data.innerDiameter = arr[2]
        result.data.innerDiameterLevel = arr[3].trim()
        result.data.grooveWidth = arr[4]
        result.data.grooveWidthLevel = arr[5].trim()
        result.data.height = arr[6]
        result.data.heightLevel = arr[7].trim()
        result.data.timeStamp = Date.now()
    }
    return result
}

var parserRule = (port) => {
    var Readline = require('@serialport/parser-readline')
    var ByteLength = require('@serialport/parser-byte-length')//指定数据帧字节长度，略
    var parser = port.pipe(new Readline({ delimiter: '\r\n' }))//以回车换行为结束标记
    return parser
}

module.exports = {
    name,
    parserRule,
    resolve
}